﻿<presentation:UserControlView x:Class="Chronos.Client.Win.Views.References.Class.View"
                              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                              xmlns:commanding="clr-namespace:Rhiannon.Windows.Presentation.Commands;assembly=Rhiannon.Windows"
                              xmlns:presentation="clr-namespace:Rhiannon.Windows.Presentation;assembly=Rhiannon.Windows"
                              xmlns:local="clr-namespace:Chronos.Client.Win.Views.References"
                              xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                              xmlns:behaviors="clr-namespace:Rhiannon.Windows.Presentation.Behaviors;assembly=Rhiannon.Windows"
                              x:Uid="Profiler_References_ClassView" Margin="0,0,0,0">
    <presentation:UserControlView.Resources>
        <local:EventToStringConverter x:Key="EventToStringConverter" />
        <HierarchicalDataTemplate x:Key="ReferenceTreeViewUnitTemplate" ItemsSource="{Binding Collection}">
            <TextBlock>
                <TextBlock Text="{Binding Item.Name}" />
                <TextBlock Text="{Binding Count, StringFormat='({0})'}" />
            </TextBlock>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate x:Key="ReferenceTreeViewEventTemplate">
            <TextBlock>
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource EventToStringConverter}">
                        <Binding Path="Item" />
                        <Binding Path="DataContext.EventNameFormatter" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type presentation:UserControlView}}" />
                    </MultiBinding >
                </TextBlock.Text>
            </TextBlock>
        </HierarchicalDataTemplate>
        <local:ReferenceTreeViewDataTemplateSelector x:Key="ReferenceTreeViewDataTemplateSelector"
                                                     UnitDataTemplate="{StaticResource ReferenceTreeViewUnitTemplate}"
                                                     EventDataTemplate="{StaticResource ReferenceTreeViewEventTemplate}"/>
    </presentation:UserControlView.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ScrollViewer Grid.Row="0">
            <TreeView ItemsSource="{Binding Reference.Collection}" ItemTemplateSelector="{StaticResource ReferenceTreeViewDataTemplateSelector}"
                      commanding:Event.Command="{Binding NavigateToEventCommand}" commanding:Event.CommandParameter="{Binding SelectedNode}"
                      commanding:Event.EventName="MouseDoubleClick">
                <interactivity:Interaction.Behaviors>
                    <behaviors:TreeViewSelectedItemBehaviour SelectedItem="{Binding DataContext.SelectedNode, Mode=OneWayToSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type presentation:UserControlView}}}" />
                </interactivity:Interaction.Behaviors>
            </TreeView>
        </ScrollViewer>
    </Grid>
</presentation:UserControlView>